/*
 * @Author       : wang chao
 * @Date         : 2023-02-16 11:06:05
 * @LastEditors: wangchao
 * @LastEditTime: 2024-10-12 08:35:35
 * @FilePath: \JD-RTT-Driver\applications\u_data.h
 * @Description  :
 * Copyright 2023 BingShan, All Rights Reserved.
 */
#ifndef _U_DATA_H_
#define _U_DATA_H_

#include <rtdevice.h>
#include <rtthread.h>
#include "board.h"

// 模拟板ADC校准参数
#define ADC0_CALI_GAIN_BASE_ADDR   400
#define ADC0_CALI_OFFSET_BASE_ADDR (ADC0_CALI_GAIN_BASE_ADDR + 32)
#define ADC1_CALI_GAIN_BASE_ADDR   (ADC0_CALI_OFFSET_BASE_ADDR + 32)
#define ADC1_CALI_OFFSET_BASE_ADDR (ADC1_CALI_GAIN_BASE_ADDR + 32)
#define ADC2_CALI_GAIN_BASE_ADDR   (ADC1_CALI_OFFSET_BASE_ADDR + 32)
#define ADC2_CALI_OFFSET_BASE_ADDR (ADC2_CALI_GAIN_BASE_ADDR + 32)
// 电压板ADC校准参数
#define CS1237_CALI_GAIN_BASE_ADDR   592
#define CS1237_CALI_OFFSET_BASE_ADDR (CS1237_CALI_GAIN_BASE_ADDR + 40)
// STM32板载DAC校准参数
#define ST_DAC1_LOW_VALUE_BASE_ADDR  672
#define ST_DAC1_HIGH_VALUE_BASE_ADDR (ST_DAC1_LOW_VALUE_BASE_ADDR + 4)
#define ST_DAC2_LOW_VALUE_BASE_ADDR  (ST_DAC1_HIGH_VALUE_BASE_ADDR + 4)
#define ST_DAC2_HIGH_VALUE_BASE_ADDR (ST_DAC2_LOW_VALUE_BASE_ADDR + 4)
// MCP4726独立DAC校准参数
#define MCP_DAC1_LV_BASE_ADDR (ST_DAC2_HIGH_VALUE_BASE_ADDR + 4)
#define MCP_DAC1_HV_BASE_ADDR (MCP_DAC1_LV_BASE_ADDR + 4)
#define MCP_DAC2_LV_BASE_ADDR (MCP_DAC1_HV_BASE_ADDR + 4)
#define MCP_DAC2_HV_BASE_ADDR (MCP_DAC2_LV_BASE_ADDR + 4)

typedef struct
{
    rt_int16_t electrolyte_temp;     // 电解液温度
    rt_int16_t bms_temp;             // BMS柜内温度
    rt_int16_t bms_humidity;         // BMS柜内湿度
    rt_int16_t p_gz_press;           // 正极罐压力
    rt_int16_t n_gz_press;           // 负极罐压力
    rt_int16_t a_p_pump_ck_press;    // 1#正极泵出口压力
    rt_int16_t a_n_pump_ck_press;    // 1#负极泵出口压力
    rt_int16_t b_p_pump_ck_press;    // 2#正极泵出口压力
    rt_int16_t b_n_pump_ck_press;    // B侧负极泵出口压力
    rt_int16_t charging_current;     // 充电电流
    rt_int16_t discharging_current;  // 放电电流
    rt_int16_t p1_flow;              // 正极1流量
    rt_int16_t p2_flow;              // 正极2流量
    rt_int16_t n1_flow;              // 负极1流量
    rt_int16_t n2_flow;              // 负极2流量
} sensor_data;

extern sensor_data app_sensor_data;

typedef struct
{
    rt_int16_t sys_total_volt;      // 系统总电压
    rt_int16_t group_a_total_volt;  // A侧总电压
    rt_int16_t group_b_total_volt;  // B侧总电压
    rt_uint16_t group_a_avr_volt;   // A侧平均电压
    rt_uint16_t group_b_avr_volt;   // B侧平均电压
    rt_int16_t sys_total_current;   // 系统总电流
    rt_int16_t sys_idle_current;    // 系统空闲电流
    rt_int16_t sys_total_power;     // 系统总功率
    rt_uint16_t group_a_soc;        // A侧SOC
    rt_uint16_t group_b_soc;        // B侧SOC
} total_power_data;

extern total_power_data power_data;
//
extern void calculate_power_data(void);

// 函数导出列表
extern rt_bool_t get_adc_calibrate_parameters(void);

#endif
